package com.easy.controller;

import com.easy.bean.Product_Size;
import com.easy.service.Product_SizeService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("product_size")
@CrossOrigin
public class Product_SizeController {

    @Autowired
    Product_SizeService product_SizeService;

    @GetMapping("/product/{productId}/sizes")
    public Result getProductSizes(@PathVariable("productId") Integer productId) {
        System.out.println("接收到获取产品尺码信息的请求，产品ID: " + productId);
        List<Product_Size> productSizes = product_SizeService.getByProductId(productId);
        System.out.println("查询结果数量: " + (productSizes != null ? productSizes.size() : 0));
        return Result.success(productSizes);
    }

    // 批量新增（新增接口）
    @PostMapping("/batch")
    public Result batchAdd(@RequestBody List<Product_Size> product_sizeList) {
        product_SizeService.batchAdd(product_sizeList);
        return Result.success(200, "批量新增成功", null);
    }

    @PostMapping
    public Result add(@RequestBody Product_Size product_size){
        return Result.success("添加成功",product_SizeService.add(product_size));
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") Integer id){
        return Result.success("删除成功",product_SizeService.del(id));
    }

    @PutMapping
    public Result edit(@RequestBody Product_Size product_size){
        product_SizeService.edit(product_size);
        return Result.success("修改信息成功",product_SizeService.one(product_size.getId()));
    }

    @GetMapping("list")
    public Result list(Product_Size product_size){
        Object obj= product_SizeService.all(product_size);
        return Result.success(obj);
    }

    @GetMapping("{id}")
    public Result select(@PathVariable("id") Integer id){
        Object obj= product_SizeService.one(id);
        return Result.success(obj);
    }

    @GetMapping("page")
    public Result page(Page page, Product_Size product_size){
        product_SizeService.page(page,product_size);
        return Result.success(page);
    }
}
